<?php
class baseModel extends model{
    //模板目录路径查找
    //path:目录路径,rootpath:锁定目录,$files:是否文件
    public function DirStop($path = null,$rootpath = FALSE,$files = FALSE){
        $themesdir = ROOT_PATH.'themes\\';
        if($rootpath){
            $themesdir = ROOT_PATH.'themes\\'.$rootpath.'\\';
        }
        if($path){
            $path = realpath($themesdir.$path);
        }else{
            $path = $themesdir;
        }
        if(!$files){
            $path = $path.DIRECTORY_SEPARATOR;
        }
        if (!file_exists($path)){
            return FALSE;
        }
        $path = str_replace('\\','/',$path);
        $themesdir = str_replace('\\','/',$themesdir);
        $newpath = strpos($path,$themesdir);
        if($newpath === 0){
            return $path;
        }else{
            return $themesdir;
        }
    }
    //查找包含目录
    public function SelectDir($path = null){
        $fileArray = NULL; 
        if(false != ($handle = opendir($path))) { 
            $i = 0; 
            while(false !== ($file = readdir ($handle))){ 
                if ($file != "." && $file != ".."){ 
                    if (is_dir($path.$file)){ 
                        $fileArray [$i] = $file; 
                    } 
                    $i ++;               
                } 
            } 
            closedir ($handle); 
        } 
        return $fileArray;
    }
    //查找文件
    //$path:更目录 $exts:*.{php,css,js,txt}
    public function SelectFile($path,$exts){
        $str = strlen($path);
        $arrdir = glob($path.$exts,GLOB_BRACE);
        if(is_array($arrdir)){
            $tpl = array();
            foreach ($arrdir as $value) {
                $tpl[] = substr($value,$str);
            }
        }
        return $tpl;
    }
}